package com.lvwenguo.utils;



import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JdbcUtils {
    private static ComboPooledDataSource c3p0datasoures=null;

    static {
        c3p0datasoures= new ComboPooledDataSource("c3p0-config");
    }

    public  ComboPooledDataSource getC3p0datasoures(){
        return c3p0datasoures;
    }
    //获取连接
    public  Connection getconnestion() throws SQLException {
        return c3p0datasoures.getConnection();
    }
    //关闭资源
    public  void close(Connection connection, PreparedStatement statement){
        if(connection!=null){
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(statement!=null){
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }


    }


}
